﻿using ElevateAVIMotion.Properties;
using ElevateAVIMotion.Tools;
using ElevateAVIMotion.View;
using ElevateAVIMotion.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ElevateAVIMotion
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : HandyControl.Controls.Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MainWindowViewModel();
            this.SetBinding(ShowInputPositionNameWindowProperty, "ShowInputPositionNameWindow ");
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            if (HandyControl.Controls.MessageBox.Show("你确定关闭软件吗？", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
            {
                Environment.Exit(-1);
            }
        }

        private void ButtonConfig_OnClick(object sender, RoutedEventArgs e) => PopupConfig.IsOpen = true;

        private void ButtonLangs_OnClick(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is Button button && button.Tag is string langName)
            {
                PopupConfig.IsOpen = false;
                ConfigHelper.Instance.SetLang(langName);
            }
        }

        public static InputPositionNameWindow InputPositionNameWindow = null;

        public static readonly DependencyProperty ShowInputPositionNameWindowProperty =
            DependencyProperty.Register("ShowInputPositionNameWindow", typeof(bool), typeof(MainWindow), new PropertyMetadata(
                new PropertyChangedCallback((d, e) =>
                {
                    if (InputPositionNameWindow != null)
                    {
                        if (InputPositionNameWindow.HasShow)
                            return;
                    }
                    var mMainWindow = d as MainWindow;
                    InputPositionNameWindow = new InputPositionNameWindow();// { Owner = this }.Show();
                    InputPositionNameWindow.Owner = Application.Current.MainWindow;
                    InputPositionNameWindow.DataContext = mMainWindow.DataContext;
                    InputPositionNameWindow.SetBinding(InputPositionNameWindow.QuitInputPositionNameWindowProperty, "QuitInputPositionNameWindow");
                    InputPositionNameWindow.HasShow = true;
                    InputPositionNameWindow.Show();
                })));
        public bool ShowInputPositionNameWindow
        {
            get { return (bool)GetValue(ShowInputPositionNameWindowProperty); }
            set { SetValue(ShowInputPositionNameWindowProperty, value); }
        }
    }
}
